package com.freak.wanandroid.model.system.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.freak.wanandroid.R;
import com.freak.wanandroid.bean.SystemClassifyBean;

import java.util.List;

/**
 * 一级分类+二级分类adapter
 *
 * @author: freak
 * @date: 2022/9/21
 */
public class SystemClassifyAdapter extends BaseQuickAdapter<SystemClassifyBean, BaseViewHolder> {

    private AppCompatActivity mAppCompatActivity;

    public SystemClassifyAdapter(int layoutResId, @Nullable List<SystemClassifyBean> data, AppCompatActivity appCompatActivity) {
        super(layoutResId, data);
        mAppCompatActivity = appCompatActivity;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, SystemClassifyBean item) {
        helper.setText(R.id.textViewTitle, item.getName());
        RecyclerView recyclerView = helper.getView(R.id.recycleViewSecondedClassify);
        SecondClassifyAdapter secondClassifyAdapter = new SecondClassifyAdapter(R.layout.item_system_second, item.getChildren());
        secondClassifyAdapter.bindToRecyclerView(recyclerView);
        recyclerView.setLayoutManager(new GridLayoutManager(mAppCompatActivity, 3));
        recyclerView.setAdapter(secondClassifyAdapter);
    }
}
